package com.msh.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

/**
 * 跨域配置
 */
@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }

    public static void main(String[] args) {
        //System.out.println(findRepeatNumber(new int[]{1,3,4,2,1}));
        System.out.println(feiBo(5));
    }


    public static int findRepeatNumber(int[] nums) {
        //新建一个数组,下标代表原数组中的元素,因此下标只需要到n-1
        int[] count=new int[nums.length];
        int ans=0;
        for(int i:nums){
            if(count[i]==0){
                count[i]++;
            }else{
                ans=i;
                break;
            }
        }
        return ans;
    }

    public static int feiBo(int n) {
        if (n == 0) return  0;
        if (n == 1) return 1;
        return feiBo(n-1)+feiBo(n-2);
    }
}
